package net.htjs.juc.deadlock.v1;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DeadLockDemo {

    public static void main(String[] args) {
        Object a = new Object();
        Object b = new Object();
        new Thread(() -> {
            synchronized (a) {
                try {
                    log.info("get lock a");
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (b) {
                    try {
                        log.info("get lock b");
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }, "t1").start();

        new Thread(() -> {
            synchronized (b) {
                try {
                    log.info("get lock b");
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (a) {
                    try {
                        log.info("get lock a");
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }, "t2").start();

    }
}
